package com.xx.pmis.services.implementations;

import java.util.List;

import com.xx.pmis.model.User;
import com.xx.pmis.persistence.dao.UserDAO;
import com.xx.pmis.services.UserService;

public class UserServiceImpl implements UserService {
	private UserDAO userDAO = null;

    public UserServiceImpl(UserDAO userDAO) {
		super();
		this.userDAO = userDAO;
	}

	// 保存或更新用户
	public void saveOrUpdateUser(User user) throws Exception {
		userDAO.saveOrUpdate(user);
	}

    // 保存用户 
	public void saveUser(User user) throws Exception {
		userDAO.save(user);
	}
	
    // 删除用户 
	public void deleteUser(User user) throws Exception {
		userDAO.delete(user);
	}

    // 查询所有用户
	public List<User> getAllUser() throws Exception {
		List<User> uesrs = userDAO.getAllUser();
		return uesrs;
	}

    // 用户登录
	public String[] login(String loginName, String userPassword)
			throws Exception {
		String us[] = new String[2];
		User user = userDAO.login(loginName, userPassword);
		if (user != null) {
			us[0] = "1";
			us[1] = user.getUserName();
		}
		return us;
	}

    // 根据用户名查询该用户
	public User getUserByUserName(String userName) throws Exception {
		User user = userDAO.getUserByUserName(userName);
		return user;
	}
    
	// 根据用户ID查询该用户
	public User getUserByUserID(String userID) throws Exception {
		User user = userDAO.getUserByUserID(userID);
		return user;
	}	

}
